# alg.py
def generate_parentheses(n):
    """生成所有有效的括号组合"""
    if n == 0:
        return []
        
    dp = [[] for _ in range(n + 1)]
    dp[0].append("")  # 0个括号时，只有一种组合，即空字符串

    for i in range(1, n + 1):
        for j in range(i):
            for left in dp[j]:
                for right in dp[i - 1 - j]:
                    dp[i].append("(" + left + ")" + right)
                    
    return dp[n]